﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace clock
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label2.Text = Convert.ToString(DateTime.Now.Hour);
            label4.Text = Convert.ToString(DateTime.Now.Minute);
            button3.Visible = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        //计时器以1分为间隔
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (textBox1.Text == label2.Text && textBox2.Text == label4.Text)
            {
                Console.WriteLine("时间到！");
                timer1.Stop();
                button2.PerformClick();
            }
            else
            {
                Console.WriteLine("滴答!");
                textBox2.Text = Convert.ToString((Convert.ToInt32(textBox2.Text) + 1));
                if (textBox2.Text == "60")
                {
                    textBox2.Text = "0";
                    textBox1.Text = Convert.ToString((Convert.ToInt32(textBox1.Text) + 1));
                    if (textBox1.Text == "24")
                    {
                        textBox1.Text = "0";
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text != "" || textBox2.Text != "") && int.Parse(textBox1.Text) >= 0 && int.Parse(textBox1.Text) <= 24 && int.Parse(textBox1.Text) >= 0 && int.Parse(textBox1.Text) <= 60)
            {
                timer1.Start();
                textBox1.ReadOnly = true;//防止篡改
                textBox2.ReadOnly = true;
                button1.Enabled = false;
                button1.Visible = false;
                button3.Enabled = true;
                button3.Visible = true;
            }
            else
            {
                MessageBox.Show("请设置合理的闹钟！");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            textBox1.ReadOnly = false;
            textBox2.ReadOnly = false;
            button3.Enabled = false;
            button3.Visible = false;
            button1.Enabled = true;
            button1.Visible = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            MyList<int> mylist = new MyList<int>();
            int cin;

            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine("please input the {0} number:", i);
                cin = Convert.ToInt32(Console.ReadLine());
                mylist.Add(cin);
            }
            Console.WriteLine("After sort:");
            Action<int> act = data => { Console.WriteLine(data); };
            mylist.ForEach(act);
            Console.ReadKey();
        }
    }
}
